﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using SQLServerHealthCheck.SQLServer;
using Microsoft.Reporting.WinForms;
using System.Configuration;


namespace SQLServerHealthCheck.PL
{
    public partial class InstallationCheckResults : Form
    {
        HealthCheckControlPanel hccp;

        public  InstallationCheckResults(HealthCheckControlPanel controlPanel)
        {
            hccp = controlPanel;
            InitializeComponent();
        }

        private void _01InstallationCheckResults_Load(object sender, EventArgs e)
        {
            try
            {



              
                this.rvServerandInstances.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(MySubreportEventHandler);


              //  List<Exception> errors= InstallationCheck.GenerateServicesOverview(hccp.SQLServerInstances);
                // TODO: This line of code loads data into the 'SQLServerHealthCheckDataSet.ServersAndInstances' table. You can move, or remove it, as needed.
                this.ServerandInstancesTableAdapter = new DataSetServerandInstancesTableAdapters.ServerandInstancesTableAdapter();
                this.ServerandInstancesTableAdapter.Connection.ConnectionString = ConfigurationManager.AppSettings["ConnectionStringSSHCDatabase"];
                this.DataSetServerandInstances = new DataSetServerandInstances();
                this.ServerandInstancesTableAdapter.Fill(this.DataSetServerandInstances.ServerandInstances);
                this.ServerandInstancesBindingSource.DataSource = this.DataSetServerandInstances;

                //this sets the sub report data
                this.TableAdapterServerandDriveDetails = new DataSetServerandDriveDetailsTableAdapters.TableAdapterServerandDriveDetails();
                this.TableAdapterServerandDriveDetails.Connection.ConnectionString = ConfigurationManager.AppSettings["ConnectionStringSSHCDatabase"];
                this.DataSetServerandDriveDetails = new DataSetServerandDriveDetails();
                this.TableAdapterServerandDriveDetails.Fill(this.DataSetServerandDriveDetails.ServerandDriveDetails);
                this.ServerandDriveDetailsBindingSource.DataSource = this.DataSetServerandDriveDetails;


                rvServerandInstances.LocalReport.ReportPath = System.Windows.Forms.Application.StartupPath + @"\Reports\ServerandInstances.rdlc";


                this.WindowState = FormWindowState.Maximized;
                
                

                this.rvServerandInstances.RefreshReport();



               
            }
            catch (NullReferenceException nex)
            {

                //InstallationCheck.WriteExceptioninFile("Form:InstallationCheckResults  Method: _01InstallationCheckResults_Load " + ex.Message.ToString());

                MessageBox.Show(nex.Message, "HealthCheck", MessageBoxButtons.OK, MessageBoxIcon.Error);                

            }

            

            
        }

        private void rvServerandInstances_Load(object sender, EventArgs e)
        {

        }


        void MySubreportEventHandler(object sender, SubreportProcessingEventArgs e)
        {
            e.DataSources.Add(new ReportDataSource("DataSet1", ServerandDriveDetailsBindingSource));
        }


    }
}
